<?php


namespace app\controller;


use think\facade\Db;

class CarWeightLog
{
    public function undoList()
    {
        $pageNum = input("pageNum") ? input("pageNum") : 1;
        $list = Db::table("JL_CZJL")->where([
            "F50" => "未完成",
            "F26" => null,
            "F27" => null,
            "F36" => "1"
        ])->paginate([
            'page' => $pageNum
        ]);

        return json([
            'code' => 1,
            'msg' => 'ok',
            'data' => $list
        ]);
    }


    public function complatedList()
    {
        $req = Request();
        $pageNum = input("pageNum") ? input("pageNum") : 1;
        $openid = $req->openid;
        $list = Db::table("JL_CZJL")
            ->where("F26", "<>", null)
            ->where("F27", "<>", null)
            ->where("F31", "=", $openid)
            ->paginate([
                'page' => $pageNum
            ]);
        return json([
            'code' => 1,
            'msg' => 'ok',
            'data' => $list
        ]);
    }

    public function updateRow()
    {
        $req = Request();
        $openid = $req->openid;
        // 查询操作人员账号信息
        $wxUser = Db::table("Sys_WeChatInf")->where("wx_h5_openid",$openid)->find();
        if(!$wxUser){
            return json([
                'code' => -1,
                'msg' => '当前登录用户未找到，请重新登陆'
            ]);
        }
        $res = Db::table("JL_CZJL")->where([
            'F2' => $req->post('carNum'),
            'F50' => "未完成",
        ])->save([
            'F26' => $req->post('shui'),
            'F27' => $req->post('za'),
            'F18' => $req->post('shui_za'),
            'F40' => $wxUser['Account'],
            'F41' => $wxUser['Name'],

            'F31' => $openid
        ]);

        return json([
            'code' => 1,
            'msg' => 'ok',
            'data' => $res
        ]);


    }

    public function markUnGood(){
        $req = Request();
        $openid = $req->openid;
        // 查询操作人员账号信息
        $wxUser = Db::table("Sys_WeChatInf")->where("wx_h5_openid",$openid)->find();
        if(!$wxUser){
            return json([
                'code' => -1,
                'msg' => '当前登录用户未找到，请重新登陆'
            ]);
        }
        $res = Db::table("JL_CZJL")->where([
            'F2' => $req->post('carNum'),
            'F50' => "未完成",
        ])->save([

            'F40' => $wxUser['Account'],
            'F41' => $wxUser['Name'],
            'F31' => $openid,
            'F50' => "已作废",
        ]);

        return json([
            'code' => 1,
            'msg' => 'ok',
            'data' => $res
        ]);
    }

    public function findCarOrderList(){
        $req = Request();
        $openid = $req->openid;
        $BianHao = $req->get("BianHao","");
        $res = Db::table("JL_CZJL")->where([
            "F3"=>$BianHao,
        ])->select()->toArray();
         return json([
            'code' => 1,
            'msg' => 'ok',
            'data' => $res
        ]);

    }
}